package DBUtil;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBManager {	
	private static String username;  //数据库用户名;
	private static String password;  //数据库用户密码
	private static String url;       //数据库连接;
	private static String driver;    //驱动程序名
	static {
			username = "root";
			password = "123456";	        
	        url = "jdbc:mysql://localhost:3306/xuanke?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC";
	        driver = "com.mysql.cj.jdbc.Driver";

	}
	//获取一个mysql的Connection对象
	public static Connection getConnection() {
		
		try {
			Class.forName(driver);
			
		return	DriverManager.getConnection(url,username,password);
				
		}catch (SQLException e) {
				e.printStackTrace();
			}
		 catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	
		}
	
	public static void close(AutoCloseable...autoCloseables) {
		if(autoCloseables!=null) {
		for(AutoCloseable autoCloseable:autoCloseables) {
			if(autoCloseable!=null) {
				try {
					autoCloseable.close();
				} catch (Exception e) {
					e.printStackTrace();
					}
				}
			}
		}
	}
	}

